﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using FarseerPhysics.Dynamics;
using FarseerPhysics.Factories;

namespace WindowsGame1
{
	public class Bullet: WorldObject
	{
		public bool isSent;
		public delegate void DisposeTrigger(Bullet b);
		public Vector2 Direction;
		public DisposeTrigger DisposeEvent;
		public Other.Damage Damage
		{
			get;
			protected set;
		}
		public BulletType Type;

		/// <summary>
		/// Creating a rectangle for each bullet to check the intersection with another object
		/// </summary>
		public Rectangle BoundingBox
		{
			get
			{
				return new Rectangle((int)Position.X - (Textures[0].Width / 2), (int)Position.Y - (Textures[0].Height / 2), Textures[0].Width, Textures[0].Height);
			}
		}

		public Bullet(Vector2 pos, float rot, float dmg, BulletType type): base(null,pos,false)
		{
			isSent = false;
			Clr = Color.Green;
			switch (type)
			{
				case BulletType.Normal:
				Textures.Add(Loader.LoadGameTexture("Bullets/bullet 1"));
				Damage = new Other.Damage(dmg);
				break;
				case BulletType.Poison:
				Textures.Add(Loader.LoadGameTexture("Bullets/bullet 2"));
				Damage = new Other.Damage(dmg * 1.5f, 4, 2, Color.Green);
				break;
				case BulletType.Water:
				Textures.Add(Loader.LoadGameTexture("Bullets/bullet 3"));
				Damage = new Other.Damage(dmg * 2, 2, 5, Color.Blue);
				break;
			}
			_size = new Point(Textures[0].Width, Textures[0].Height);
			Direction = Config.AngleToVector(rot);
			Rotation = rot;
			Position = pos;
			Type = type;
		}
		
		public void DisposeBullet()
		{
			if (DisposeEvent != null)
			{
				DisposeEvent.Invoke(this);
			}
		}

		/// <summary>
		/// Update bullet
		/// </summary>
		/// <param name="direction">the direction of the bullet where it goes to</param>
		public void Update()
		{
			Position += Direction * Config.BulletSpeed;           
		}


	}
}
